package com.tms.springboot.controller;


import com.github.pagehelper.PageInfo;
import com.tms.springboot.aggregation.pojo.PdFleet;
import com.tms.springboot.base.pojo.PdTruckDriver;
import com.tms.springboot.base.pojo.PdTruckDriverLicense;
import com.tms.springboot.base.pojo.PdTruckLicense;
import com.tms.springboot.service.PdTruckDriverService;
import com.tms.springboot.vo.PdTruckDriverBasicInfoVo;
import com.tms.springboot.vo.PdTruckDriverInfoVo;
import com.tms.springboot.vo.PdTruckDriverVo;
import com.tms.springboot.vo.PdTruckVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;



/**
 * <p>
 * 司机表 前端控制器
 * </p>
 *
 * @author xiaoyang
 * @since 2023-06-14
 */
@RestController
@RequestMapping("/pd-truck-driver")
public class PdTruckDriverController {

    @Autowired
    PdTruckDriverService service;


    /***
     * TODO 新增司机的基本信息
     * @return
     */
    @PostMapping("addTruckDriver")
    public boolean addPdTruckDriver(@RequestBody PdTruckDriver driver){
        if (ObjectUtils.isEmpty(driver)){
            throw new IllegalArgumentException("driver 不能为空！");
        }
        return this.service.save(driver);
    }

    /***
     * TODO 修改司机的所属车队
     * @param pdTruckDriverInfoVo
     * @return
     */
    @PostMapping("updateDriverFleetId")
    public Boolean updateTruckDriverFleetId(@RequestBody PdTruckDriverInfoVo pdTruckDriverInfoVo){
        if (StringUtils.isEmpty(pdTruckDriverInfoVo.getUserId())){
            throw new IllegalArgumentException("userId is null");
        }
        if (StringUtils.isEmpty(pdTruckDriverInfoVo.getFleetId())){
            throw new IllegalArgumentException("fleetId is null");
        }
        PdTruckDriver pdTruckDriver = this.service.queryDriverByUserIdService(pdTruckDriverInfoVo.getUserId());

        pdTruckDriver.setFleetId(pdTruckDriverInfoVo.getFleetId());

        return this.service.updateById(pdTruckDriver);
    }

    /***
     * TODO 删除司机信息
     * @param id
     * @return
     */
    @PostMapping("removeDriver/{id}")
    public Boolean removeDriver(@PathVariable String id){
        if (StringUtils.isEmpty(id)){
            throw new IllegalArgumentException("id is null");
        }
        return this.service.removeById(id);
    }


    /***
     * TODO 条件查询司机信息
     * @param pdTruckDriverVo
     * @return
     */
    @PostMapping("queryAllDriverInfo")
    public PageInfo<PdTruckDriverInfoVo> queryAllDriver(@RequestBody PdTruckDriverVo pdTruckDriverVo){
        return this.service.queryDriverInfoService(pdTruckDriverVo);
    }

    /***
     * TODO 根据司机编号查询
     * @param id
     * @return
     */
    @PostMapping("queryDriverBasicInfoById/{id}")
    public PdTruckDriverBasicInfoVo queryDriverBasicInfoById(@PathVariable String id){
        return this.service.queryDriverBasicInfoByIdService(id);
    }

    /***
     * TODO 根据用户id 查询车辆信息
     * @param id
     * @return
     */
    @PostMapping("queryCarInfo/{id}")
    public PdTruckVo queryTruckInfo(@PathVariable String id){
        return this.service.queryTruckByIdService(id);
    }


    /***
     * TODO 根据用户id 查询驾驶证信息
     * @param id
     * @return
     */
    @PostMapping("queryLicenseByUserId/{id}")
    public PdTruckDriverLicense queryLicenseByUserId(@PathVariable String id){
        return this.service.queryLicenseByUserIdService(id);
    }


    /***
     * 修改司机驾驶证信息
     * @param pdTruckDriverLicense
     * @return
     */
    @PostMapping("updLicenseById")
    public Boolean updateLicenseById(@RequestBody PdTruckDriverLicense pdTruckDriverLicense){
        return this.service.updLicenseByIdService(pdTruckDriverLicense);
    }



}
